package com.bcqn.controller;

import com.alibaba.fastjson.JSONObject;
import com.bcqn.common.CommonResponse;
import com.bcqn.model.PostReview;
import com.bcqn.service.PostReviewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * PostReviewController
 *
 * @author Kelly
 * @version v1.0
 * @date 2020/4/17 20:44
 */
@RestController
@RequestMapping("/postReview")
@Slf4j
public class PostReviewController {

    @Autowired
    private PostReviewService postReviewService;

    /**
     * 帖子评论
     * @param postReview
     * @return
     */
    @PostMapping("/update")
    public CommonResponse update(PostReview postReview) {
        return CommonResponse.success(postReviewService.update(postReview));
    }


    /**
     * 删除帖子评论
     * @param reviewId
     * @param userId
     * @return
     */
    @DeleteMapping("/delete")
    public CommonResponse delete(@RequestParam Long reviewId, @RequestParam Long userId) {
        return CommonResponse.success(postReviewService.delete(reviewId,userId));
    }

    /**
     * 评论的点赞或者取消点赞
     * @param reviewId
     * @param userId
     * @param likeStatus
     * @return
     */
    @PostMapping("/updateLike")
    public CommonResponse updateLike(@RequestParam Long reviewId, @RequestParam Long userId, @RequestParam Integer likeStatus) {
        return CommonResponse.success(postReviewService.updateLike(reviewId,userId,likeStatus));
    }

    /**
     * 根据帖子id查询评论
     */
    @GetMapping("/getByPostId")
    public CommonResponse getByPostId(@RequestParam Long postId,@RequestParam Long userId,@RequestParam Integer orderType,@RequestParam Integer pageNum, Integer pageSize) {
        return CommonResponse.success(postReviewService.getByPostId(postId,userId,orderType,pageNum,pageSize));
    }

    /**
     * 根据评论的id查询子评论
     */
    @GetMapping("/getById")
    public CommonResponse getById(@RequestParam Long id,@RequestParam Long userId,@RequestParam Integer pageNum, Integer pageSize) {
        return CommonResponse.success(postReviewService.getById(id,userId,pageNum,pageSize));
    }






}
